home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / asm / libmacro.lha / example.library.S next >
Text File  |  1995-04-17  |  2KB  |  114 lines

  1. ;##############################################################################
  2. ;
  3. ; $VER: example.library 1.1 (13.4.1995)  Rudla Kudla
  4. ;
  5. ;##############################################################################
  6.  
  7.         INCDIR    "INCLUDES:"
  8.         INCLUDE    "exec/types.i"
  9.         INCLUDE    "exec/macros.i"
  10.         INCLUDE    "exec/exec_lib.i"
  11.         INCLUDE    "exec/libraries.i"
  12.         INCLUDE    "kudlar/library.i"
  13.  
  14. ;======    Declare library base structure (that extra long after LIB_SIZE is
  15. ;    used to store library segment, see init and close) and count it's
  16. ;    size.
  17.  
  18.         STRUCTURE ExampleBase,LIB_SIZE+4
  19.  
  20.         ;Here insert declarations of your own variables
  21.  
  22.         LABEL    ex_SIZEOF
  23.  
  24.  
  25. ;======    Define library header and declare function names
  26.  
  27.         LIBRARY    example,1,0,5.3.1995,ex_SIZEOF
  28.         ;    name,version,revision,date,librarybase size
  29.  
  30.         LIBRARY    FUNCTIONS
  31.         LIBRARY    OpenLib,CloseLib,ExpungeLib,ExtFuncLib
  32.  
  33.         ;Here insert your library functions names (as shown on
  34.         ;UserAdd, UserSub and UserMul). LIBRARY macro can be followed
  35.         ;with upto 9 names of functions.
  36.  
  37.         LIBRARY    UserAdd,UserSub
  38.         LIBRARY    UserMul
  39.  
  40. ;======    Following functions are required. They are used when openning or
  41. ;    closing library. You can however modify them as you wish.
  42.  
  43.         LIBRARY    CODE
  44.  
  45.         LIBRARY    Init
  46.         exg    a0,d0
  47.         move.l    d0,LIB_SIZE(a0)
  48.         exg    a0,d0
  49.  
  50.         ;You will probably want to make some initializations here.
  51.         ;Remember, that you must return all registers (including
  52.         ;d0-d1/a0-a1) unchanged.
  53.  
  54.         rts
  55.  
  56.  
  57.         LIBRARY    OpenLib    
  58.         add.w    #1,LIB_OPENCNT(a6)
  59.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  60.         move.l    a6,d0
  61.         rts
  62.  
  63.         LIBRARY    CloseLib
  64.         subq.w    #1,LIB_OPENCNT(a6)
  65.         bne.b    ExtFuncLib
  66.         btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  67.         beq.b    ExtFuncLib
  68.  
  69.         LIBRARY    ExpungeLib
  70.         movem.l    d2/a5/a6,-(sp)
  71.         tst.w    LIB_OPENCNT(a6)
  72.         bne.b    .still_openned
  73.  
  74.         ;On this place free all resources which has been
  75.         ;allocated in init part. a6 contain library base.
  76.  
  77.         move.l    LIB_SIZE(a6),d2
  78.         move.l    a6,a5
  79.         move.l    4.w,a6
  80.         move.l    a5,a1
  81.         JSRLIB    Remove
  82.         move.l    a5,a1
  83.         moveq    #0,d0
  84.         move.w    LIB_NEGSIZE(a5),d0
  85.         sub.w    d0,a1
  86.         add.w    LIB_POSSIZE(a5),d0
  87.         JSRLIB    FreeMem
  88.         move.l    d2,d0
  89.         movem.l    (sp)+,d2/a5/a6
  90.         rts
  91.  
  92. .still_openned
  93.         bset    #LIBB_DELEXP,LIB_FLAGS(a6)
  94.  
  95.         LIBRARY    ExtFuncLib
  96.         moveq    #0,d0
  97.         rts
  98.  
  99. ;======    Now follows code for all declared library specific functions.
  100.  
  101.         LIBRARY    UserAdd
  102.         add.l    d1,d0
  103.         rts
  104.  
  105.         LIBRARY    UserSub
  106.         sub.l    d1,d0
  107.         rts
  108.  
  109.         LIBRARY    UserMul
  110.         mulu    d1,d0
  111.         rts
  112.         
  113.         LIBRARY    END
  114.